<template>
	<el-form label-width="140px" :model="form" :rules="rules" ref="queryForm">
		<el-row>
			<el-col :span="12">
				<el-form-item label="车站名称" prop="name">
					<el-input v-model="form.name" style="width: 190px;"></el-input>
				</el-form-item>
				
				<el-form-item label="行政区域" prop="district">
					<el-select v-model="form.district" size="default" placeholder="请选择" style="width: 190px" clearable
						filterable>
						<el-option v-for="item in options" :key="item.dictValue" :label="item.dictLabel"
							:value="item.dictValue" />
					</el-select>
				</el-form-item>
				
				<el-form-item label="经度" prop="longitude">
					<el-input v-model="form.longitude" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'longitude', 12)"></el-input>
				</el-form-item>
				
				<el-form-item label="纬度" prop="latitude">
					<el-input v-model="form.latitude" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'latitude', 12)"></el-input>
				</el-form-item>
				
				<el-form-item label="海拔" prop="elevation">
					<el-input v-model="form.elevation" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'elevation', 2)"></el-input>
				</el-form-item>
				<el-form-item label="详细地址" prop="detailedAddress">
					<el-input v-model="form.detailedAddress" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="用地面积" prop="area">
					<el-input v-model="form.area" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'area', 2)"></el-input>
				</el-form-item>
				
			</el-col>
			<el-col :span="12">
				
				<el-form-item label="可停车数量" prop="stop">
					<el-input v-model="form.stop" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'stop', 4)"></el-input>
				</el-form-item>

				<el-form-item label="最大设计量" prop="max">
					<el-input v-model="form.max" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'max', 0)"></el-input>
				</el-form-item>

				<el-form-item label="日均量" prop="avg">
					<el-input v-model="form.avg" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'avg', 0)"></el-input>
				</el-form-item>

				<el-form-item label="高峰量" prop="high">
					<el-input v-model="form.high" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'high', 0)"></el-input>
				</el-form-item>

				<el-form-item label="联系人" prop="contact">
					<el-input v-model="form.contact" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="联系电话" prop="contactPhone">
					<el-input v-model="form.contactPhone" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'contactPhone', 0)"></el-input>
				</el-form-item>

			</el-col>
		</el-row>
		<div style="display: flex;justify-content: flex-end;">
			<el-button @click="closethis()" @keyup.prevent @keydown.enter.prevent>取消</el-button>
			<el-button type="primary" @click="submit(queryForm)" @keyup.prevent @keydown.enter.prevent>确定</el-button>
		</div>
	</el-form>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted
	} from 'vue'
	import {
		ElMessage
	} from 'element-plus'

	import {
		commonInterface
	} from '@/api/common/common'
	
	import {
		regOnlyNumSpot
	} from '@/utils/reg'



	const emit = defineEmits(['getList', 'closeWindow'])
	const props = defineProps(['editData', 'options'])

	const form = ref({})

	const queryForm = ref('')

	const options = ref()

	//必填项
	const rules = reactive({
		name: [{
			required: true,
			message: "此选项不能为空!",
			trigger: "blur"
		}]
	})
	//取消
	const closethis = () => {
		emit('closeWindow')
	}

	//确定
	const submit = async (e) => {
		if (!e) return
		await e.validate((valid) => {
			if (valid) {
				let method = 'post'
				if (props.editData) method = 'put'
				commonInterface('/back/renfang/zcbz/hystation/', form.value, method).then(result => {
					if (result.code === 200) {
						ElMessage.success(result.msg)
						emit('closeWindow')
						emit('getList')
					} else {
						ElMessage.error(result.msg)
					}
				})
			}
		})
	}

	onMounted(() => {
		options.value = props.options
		if (props.editData) form.value = props.editData
	})
</script>

<style>
</style>